#!/bin/sh

#数据库名字
HIVE_DB=dataplatform_huashen
CUR_DIR=$(cd "$(dirname "$0")"; pwd)
START_TIME=`date +%s`
hive --hiveconf "tez.queue.name=hive" -e "create database if not exists ${HIVE_DB}"
echo "创建Hive表开始..."
#ls  ${CUR_DIR}/hive/hql |xargs -n1 |grep -v create_database.hql | xargs -n 1 -I {} hive -hivevar hive_db=${HIVE_DB} -hivevar hbase_ns=${HBASE_NS} -hivevar data_dir=${CUR_DIR}/hive/data -f "${CUR_DIR}/hive/hql/{}"
for f in `ls ${CUR_DIR}/*/*.[sh]ql`
do
    hive -hivevar hive_db=${HIVE_DB} -f $f
    if [ $? -ne 0 ] ; then
        echo "${f}执行失败..."
    else
	    echo "${f}执行成功..."
    fi
done

echo "创建Hive表结束，耗时$((`date +%s`-START_TIME))秒..."
hive -e "use ${HIVE_DB}; show tables;"